/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package toesp.util;

import java.awt.Component;
import javax.swing.JOptionPane;

/**
 *
 * @author satria
 */
public class joptionPaneUtil {
    private int[] messageTypes = { JOptionPane.PLAIN_MESSAGE,
			JOptionPane.INFORMATION_MESSAGE, JOptionPane.QUESTION_MESSAGE,
			JOptionPane.WARNING_MESSAGE, JOptionPane.ERROR_MESSAGE };
	 
    private int[] OptionTypes = { JOptionPane.DEFAULT_OPTION,
                    JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.OK_CANCEL_OPTION };

    
    public void showDialog(Component compParent,String strTitle,Object objMessage,int intMessageType){
        JOptionPane.showMessageDialog(compParent,objMessage,strTitle,messageTypes[intMessageType]);
    }
    
    public void showDialogPlain(Component compParent,String strTitle,Object objMessage){
        JOptionPane.showMessageDialog(compParent,objMessage,strTitle,messageTypes[0]);
    }
    
    public void showDialogInfo(Component compParent,String strTitle,Object objMessage){
        JOptionPane.showMessageDialog(compParent,objMessage,strTitle,messageTypes[1]);
    }
    
    public void showDialogInfo(Object objMessage){
        JOptionPane.showMessageDialog(null,objMessage,"Information",messageTypes[1]);
    }
    
    public void showDialogQuestion(Component compParent,String strTitle,Object objMessage){
        JOptionPane.showMessageDialog(compParent,objMessage,strTitle,messageTypes[2]);
    }
    
    public void showDialogQuestion(Object objMessage){
        JOptionPane.showMessageDialog(null,objMessage,"Question",messageTypes[3]);
    }
    
    public void showDialogWarning(Component compParent,String strTitle,Object objMessage){
        JOptionPane.showMessageDialog(compParent,objMessage,strTitle,messageTypes[3]);
    }
    
    public void showDialogWarning(Object objMessage){
        JOptionPane.showMessageDialog(null,objMessage,"Warning",messageTypes[3]);
    }
    
    public void showDialogError(Component compParent,String strTitle,Object objMessage){
        JOptionPane.showMessageDialog(compParent,objMessage,strTitle,messageTypes[4]);
    }
    
    public void showDialogError(Object objMessage){
        JOptionPane.showMessageDialog(null,objMessage,"Error",messageTypes[4]);
    }
    
    public int msgConfirm(Component compParent,String strTitle,Object objMessage,int intOptionType,int intMessageType){
        int intConfirm = JOptionPane.showConfirmDialog(compParent, objMessage, strTitle, intOptionType, intMessageType);
        return intConfirm;
    }
    
    public int msgConfirmQuestion(Component compParent,String strTitle,Object objMessage){
        int intConfirm = JOptionPane.showConfirmDialog(compParent, objMessage, strTitle, OptionTypes[1], messageTypes[2]);
        return intConfirm;
    }
    
    public int msgConfirmQuestion(Component compParent,Object objMessage){ // 1 No , 0 Yes
        int intConfirm = JOptionPane.showConfirmDialog(compParent, objMessage, "Confirmation", OptionTypes[1], messageTypes[2]);
        return intConfirm;
    }
    
    public int msgOption(Component compParent,String strTitle,Object objMessage,Object[] options,int intDefaultOption){
        int intConfirm = JOptionPane
                        .showOptionDialog(compParent,
                                          objMessage,
                                          strTitle,
                                          OptionTypes[1],
                                          messageTypes[2],
                                          null,     //do not use a custom Icon
                                          options,  //the titles of buttons
                                          options[intDefaultOption]); //default button title

        return intConfirm;
    }
    
    public String msgInputDialog(Component compParent,String strTitle,Object objMessage){
        return JOptionPane.showInputDialog(compParent, objMessage, strTitle, messageTypes[2]);
    }
}
